package com.fragmenttest;

import java.util.ArrayList;

import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.app.ListActivity;
import android.database.Cursor;
import android.view.Menu;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class MainActivity extends ListActivity {

	@SuppressWarnings("deprecation")
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		//setContentView(R.layout.activity_main);
		
		TextView view = new TextView(this);
		//ListView list = (ListView) findViewById(R.id.listView1);
		ArrayList<String> smslist = new ArrayList<String>();
		//String[] mylist = {"my name", "is ..."};
		
	      Uri uriSMSURI = Uri.parse("content://sms/inbox");
	      Cursor cur = getContentResolver().query(uriSMSURI, null, null, null,null);
	      String sms = "";
	      while (cur.moveToNext()) {
	    	  
	    	  if(cur.getString(12).contains("offer") || cur.getString(12).contains("Offer"))
	    	  {
	    		smslist.add(cur.getString(12));
	          sms += "From :" + cur.getString(2) + " : " + cur.getString(12)+ "\n\n";
	    	  }
	      }
	      //smslist.add("prabhu");
	      //smslist.add("gnana");
	      
	    //ArrayAdapter<String> arrayAdapter =      
	      ListAdapter arrayAdapter =
	    	      new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, smslist);
	    		//new ArrayAdapter<String>(this,R.id.listView1, smslist);
	    setListAdapter(arrayAdapter);
	      
	    view.setText(sms);
		setContentView(R.layout.activity_main);

	    //setContentView(list);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}
